<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.$_RQ['nickname'].'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['username'])){
		$params['username like']='%'.$_RQ['username'].'%';
		$return['params']['username']=$_RQ['username'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('mid','idcard_check','wallet_pledge','wallet_pledge_freeze','createtime');
	$list=pdo_getslice('jy_jdpm_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			if(!isset($item['idcard_check'])){
				$item['idcard_check']=0;
			}
			$member = get_member($item['mid']);
			$item=array_merge($item,$member);
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['email']=$item['email']?$item['email']:'无';	
			$item['pcd']=$item['prov'].$item['city'].$item['district'];	
			$item['nickname']=$item['nickname'] ? $item['nickname']:'昵称:云拍校尉';
			$item['avatar']=$item['avatar']?$item['avatar']:'../addons/jy_jdpm/resource/images/userlogo.jpg';
			$item['able']=price($item['credit2']-$item['wallet_pledge_freeze']);
			$item['userinfo']=$item['avatar'].'账号：'.$item['username'].'\n'.'昵称:'.$item['nickname'];
			$item['sex'] = $item['sex'] ? '(男)' : '(女)';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户管理'),
			array('op'=>'edit','title'=>'添加用户'),
		),
		'export'=>'export',
		'export_title'=>'导出用户数据',
		'list'=>array('key'=>'mid','data'=>'list','delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('type'=>'img_string','title'=>'登录账号','img'=>'avatar',
			'data'=>array(
				array('title'=>'账号：','name'=>'username'),
				array('title'=>'昵称：','name'=>'nickname','unit'=>'sex')
				)
			),
			array('title'=>'邮箱/手机号','type'=>'img_string',
			'data'=>array(
				array('title'=>'邮箱：','name'=>'email'),
				array('title'=>'手机号码：','name'=>'mobile')
				)
			),
			array('name'=>'wallet_pledge','title'=>'总余额','type'=>'string'),
			array('name'=>'wallet_pledge_freeze','title'=>'冻结余额','type'=>'string'),
			array('name'=>'able','title'=>'可用余额','type'=>'string'),
			array('name'=>'pcd','title'=>'地区','type'=>'string'),
			array('title'=>'登录ip/注册时间','type'=>'img_string',
			'data'=>array(
				array('title'=>'登陆IP：','name'=>'reg_ip'),
				array('title'=>'注册于：','name'=>'createtime')
				)
			),
		
		),'action'=>array(	
			array('op'=>'sendsms','title'=>'发送站内信','type'=>'modal'),
			array('type'=>'href','op'=>'log','title'=>'资金明细'),
			array('type'=>'href','op'=>'tixian','title'=>'提现明细'),
			array('op'=>'credit','title'=>'余额/信誉','type'=>'modal'),	
			//array('type'=>'post','op'=>'del','title'=>'删除','message'=>'确定删除?'),			
		),),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'会员UID','name'=>'mid','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'用户账号','name'=>'username','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'昵称','name'=>'nickname','help'=>''),
		),
	);
	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='log'){
	if($_RQ['mid']){
		$_SESSION['loguid']=$_RQ['mid'];
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_RQ['mid']
		);
	}else{
		$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['loguid']
		);
	}
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type'];
		$return['params']['type']=$_RQ['type'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';	
	$list=pdo_getslice('jy_jdpm_money_log',$params,array($pindex,$psize),$total,'','','create_time desc');
	$type=$this->feetypes();
	if($list){
		foreach($list as &$item){
			$t=$item['type'];
			$item['type']=$type[$t];
			$item['create_time']=date('Y/m/d H:i:s',$item['create_time']);	
			$item['pname']=pdo_getcolumn('jy_jdpm_auction',array('pid'=>$item['pid']),'pname');	
			$item['pname']=$item['pname']?$item['pname']:'';		
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户管理'),
		),
		'export'=>'export1',
		'export_title'=>'导出用户资金明细',
		'list'=>array('edit'=>false,'data'=>'list','delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('name'=>'pname','title'=>'拍卖名称','type'=>'string'),
			array('name'=>'money','title'=>'金额','type'=>'string'),
			array('name'=>'type','title'=>'类型','type'=>'string'),
			array('name'=>'channel','title'=>'渠道','type'=>'radio','options'=>'channel'),
			array('name'=>'remarks','title'=>'备注','type'=>'string'),
			array('name'=>'create_time','title'=>'变动时间','type'=>'string'),
			
		
		),),
		'search'=>array(
			array('type'=>'select','width'=>'15','title'=>'类型','name'=>'type','options'=>'type2','select_title'=>'请选择类型'),
		),
	);
	$return['type']=$this->feetypes();
	$return['type2']=array(
		array('id'=>0,'title'=>'充值'),
		array('id'=>1,'title'=>'保证金'),
		array('id'=>2,'title'=>'支付订单'),
		array('id'=>3,'title'=>'拍品分享金'),
		array('id'=>4,'title'=>'拍品收入'),
		array('id'=>5,'title'=>'手续费/平台服务费'),
		array('id'=>6,'title'=>'过期订单未支付扣除'),
		array('id'=>7,'title'=>'推广佣金'),
		array('id'=>8,'title'=>'过期订单收取违约金'),
	);
	$return['channel']=array('1'=>'进账','2'=>'出账');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='tixian'){
	if($_RQ['mid']){
		$_SESSION['tixianuid']=$_RQ['mid'];
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_RQ['mid']
		);
	}else{
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['tixianuid']
		);
	}
	if(isset($_RQ['status'])){
		$params['status']=$_RQ['status'];
		$return['params']['status']=$_RQ['status'];
	}
	 
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','mid','money','paytype','bank','bankhome','wechat','alipay','name','username','remark','createtime','dtime','status','type','mission');
	$list=pdo_getslice('jy_jdpm_member_pledge_take',$params,array($pindex,$psize),$total,$fields,'','time desc');
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('jy_jdpm_member',array('mid'=>$item['mid']),array('nickname','avatar','username'));
			$item['nickname']=$item['member']['nickname'];
			$item['uaccount']=$item['member']['username'];
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['dtime']=$item['dtime']?date('Y/m/d H:i:s',$item['dtime']):'';
			$item['bankhome']=$item['bankhome']?$item['bankhome']:'空';
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户列表'),
		),
		'export'=>'exporttx',
		'export_title'=>'导出提现数据',
		'list'=>array('key'=>'id','data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'用户UID','type'=>'string'),
			array('name'=>'uaccount','title'=>'用户账号','type'=>'string'),
			array('name'=>'money','title'=>'提现金额','type'=>'string'),
			array('name'=>'mission','title'=>'手续费用','type'=>'string','options'=>'order_types'),
			array('name'=>'username','title'=>'收款账户','type'=>'string'),
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'bank','title'=>'开户行','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string','options'=>'order_status','set'=>'set'),
			array('name'=>'createtime','title'=>'申请时间','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'dtime','title'=>'处理时间','type'=>'string'),
		
		),
			
		),
		'search'=>array(
			array('type'=>'select','width'=>'15','title'=>'状态','name'=>'status','options'=>'status2'),
		),	
	);
	$return['status']=array('0'=>'等待转账','1'=>'已转账','2'=>'驳回提现');
	$return['status2']=array(
		array('id'=>0,'title'=>'等待转账'),
		array('id'=>1,'title'=>'已转账'),
		array('id'=>2,'title'=>'驳回提现'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='exporttx'){
	//导出体现数据
	if($_RQ['mid']){
		$_SESSION['tixianuid']=$_RQ['mid'];
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_RQ['mid']
		);
	}else{
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['tixianuid']
		);
	}
	if(isset($_RQ['status'])){
		$params['status']=$_RQ['status'];
		$return['params']['status']=$_RQ['status'];
	}
	 
	$list=pdo_getall('jy_jdpm_member_pledge_take',$params,array(),'','time asc');
	if($list){
		$status=array(
			'0'=>'等待退款',
			'1'=>'已退款',
			'2'=>'已驳回',
		);
		$type=array(
			'0'=>'招商银行',
			'1'=>'他行实时',
			
		);
		foreach($list as &$item){
			
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['dtime']=date('Y/m/d H:i:s',$item['dtime']);
			if($item['status']==2){
				$item['ddtime']=$item['dtime'];
				$item['dtime']='';
			}
			if($item['status']!=1){
				$item['dtime']='';
			}
			$item['status']=$status[$item['status']];
			$item['type']=$type[$item['type']];
			$item['url']=manage_url('jy_jdpm/membermoney/log',true).'/uid='.$item['mid'];
		}
	}
	$header=array(
		'mid'=>'付方账号',
		'money'=>'金额上限',
		'zhipiao'=>'支票权限',
		'shouquan'=>'授权使用人',
		'settype'=>'收方信息填写类型',
		'username'=>'收方账号',
		'name'=>'收方户名',
		'type'=>'汇路类型',
		'bank'=>'收方行名称',
		'bankhome'=>'收方行行号',
		'address'=>'收方行地址',
		'cause'=>'附言',
		'phone'=>'收款人手机号码',
		'url'=>'个人交易详情',
		'createtime'=>'申请时间',
		'dtime'=>'处理日期',
		'mission'=>'手续费',
	);
	cfc('tools')->export2excel($header,$list,'用户UID：'.$_SESSION['tixianuid'].'提现数据'.date('Y/m/d',time()));
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.$_RQ['nickname'].'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['username'])){
		$params['username like']='%'.$_RQ['username'].'%';
		$return['params']['username']=$_RQ['username'];
	}
	if(isset($_RQ['idcard_check'])){
		$params['idcard_check']=$_RQ['idcard_check'];
		$return['params']['idcard_check']=$_RQ['idcard_check'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('mid','idcard_check','wallet_pledge','wallet_pledge_freeze','idcard_check','idcard','truename');
	$list=pdo_getslice('jy_jdpm_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		$idcard_check=array(
			'0'=>'未申请认证',
			'1'=>'待认证',
			'2'=>'已认证',
			'3'=>'未通过'
		);
		foreach($list as &$item){
			$member = get_member($item['mid']);
			$item=array_merge($item,$member);
			if(!isset($item['idcard_check'])){
				$item['idcard_check']=0;
			}
			$item['able']=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['idcard_check']=$idcard_check[$item['idcard_check']];
			
			
		}
	}
	$header=array(
		'mid'=>'mid',
		'username'=>'用户账号',
		'nickname'=>'昵称',
		'mobile'=>'手机号',
		'wallet_pledge'=>'总余额',
		'wallet_pledge_freeze'=>'冻结余额',
		'able'=>'可用余额',
		'createtime'=>'注册时间',
		'idcard_check'=>'身份认证状态',
	);
	cfc('tools')->export2excel($header,$list,'用户数据-'.date('Y-m-d'));
}
if($_RQ['op']=='export1'){
	if($_RQ['mid']){
		$_SESSION['loguid']=$_RQ['mid'];
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_RQ['mid']
		);
	}else{
		$params=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['loguid']
			);
	}
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type'];
		$return['params']['type']=$_RQ['type'];
	}
	
	
	$list=pdo_getall('jy_jdpm_money_log',$params,'','','create_time desc');
	$type=$this->feetypes();
	$channel=array('1'=>'进账','2'=>'出账');
		if($list){
		foreach($list as &$item){
			$t=$item['type'];
			$item['type']=$type[$t];
			$c=$item['channel'];
			$item['channel']=$channel[$c];
			$item['create_time']=date('Y/m/d H:i:s',$item['create_time']);	
			$item['pname']=pdo_getcolumn('jy_jdpm_auction',array('pid'=>$item['pid']),'pname');	
			$item['pname']=$item['pname']?$item['pname']:'';		
		}
	}
	$header=array(
		'mid'=>'mid',
		'pname'=>'拍卖名称',
		'money'=>'金额',
		'type'=>'类型',
		'channel'=>'渠道',
		'remarks'=>'备注',
		'create_time'=>'变动时间',
	);
	cfc('tools')->export2excel($header,$list,'用户id:'.$_SESSION['loguid'].'资金明细-'.date('Y-m-d'));
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['mid']);
	if($id){
		$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['pcd']=json_decode($item['pcd'],true);
		$item['paypwd']='';
		$item['password']='';
	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['verify']=array('0'=>'未认证','1'=>'已认证');
	$return['check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$return['sex']=array('0'=>'女','1'=>'男');
	$return['status']=array('0'=>'禁用','1'=>'启用');
	$return['pcd']=cfc('tools')->pcd();
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回会员列表'),
			
		),
		'desc'=>'会员信息设置',
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','name'=>'username','title'=>'登录账号','help'=>'不可重复'),
					array('type'=>'string','name'=>'password','title'=>'密码','help'=>'不修改留空'),
					array('type'=>'string','name'=>'paypwd','title'=>'支付密码','help'=>'不修改留空'),
					array('type'=>'image','name'=>'avatar','title'=>'头像','help'=>'图片尺寸：正方形图片'),
					array('type'=>'string','name'=>'nickname','title'=>'昵称'),
					array('type'=>'string','name'=>'scorebuy','title'=>'买家得分','help'=>'重置满多少可用, 空或0 不限制'),
					array('type'=>'time','name'=>'birthday','title'=>'生日'),
					array('type'=>'radio','name'=>'sex','title'=>'性别','options'=>'sex'),
					array('type'=>'string','name'=>'email','title'=>'邮箱'),
					array('type'=>'radio','name'=>'verify_email','title'=>'邮箱认证','options'=>'verify'),
					array('type'=>'string','name'=>'mobile','title'=>'手机号'),
					array('type'=>'radio','name'=>'verify_mobile','title'=>'手机号认证','options'=>'verify'),
					array('type'=>'string','name'=>'phone','title'=>'固定电话'),
					array('type'=>'string','name'=>'postalcode','title'=>'邮编'),
					array('type'=>'pcd','name'=>'pcd','title'=>'所在地','options'=>'pcd'),
					array('type'=>'string','name'=>'address','title'=>'街道地址','help'=>'不需要写省市区, 必须大于五个字符'),	
					array('type'=>'radio','name'=>'status','title'=>'状态','options'=>'status'),						
					
		)
	),
			array(
				'title'=>'实名认证',
				'list'=>array(
					
					array('type'=>'string','name'=>'truename','title'=>'真实姓名'),
					array('type'=>'string','name'=>'idcard','title'=>'身份证号'),
					array('type'=>'image','name'=>'idcard_front','title'=>'身份证正面照片'),
					array('type'=>'image','name'=>'idcard_behind','title'=>'身份证反面照片'),
					array('type'=>'radio','name'=>'idcard_check','options'=>'check','title'=>'实名认证'),					
				)
			),
			array(
				'title'=>'卖家信息',
				'list'=>array(
					array('type'=>'string','name'=>'score','title'=>'卖家得分'),
					array('type'=>'string','name'=>'title','title'=>'店铺名称'),
					array('type'=>'string','name'=>'desc','title'=>'店铺简介'),
					array('type'=>'image','name'=>'logo','title'=>'店铺logo','help'=>'图片尺寸：正方形图片'),
								
				)
			)
	)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$id=intval($post['mid']);
	
	$a=pdo_getcolumn('jy_jdpm_member',array('username'=>trim($post['username']),'uniacid'=>$_SESSION['uniacid']),'mid');
	if($a && $id!=$a){
		exi('用户名重复，请重新输入','error');
	}
	$data=array_fields(array('username','avatar','postalcode','nickname','scorebuy','birthday','sex','email','verify_email','mobile','mobile_email',
	'phone','address','status','truename','idcard','idcard_front','idcard_behind','idcard_check','score'),$post);
	$data['pcd']=ijson_encode($data['pcd']);
	if($post['paypwd']){
		$data['paypwd']=encryptPwd(trim($post['newpaypwd']));
	}
	if($post['password']){
		$data['password']=encryptPwd(trim($post['password']));
	}
	if($id){
		if($data['pwd']){
			$mid=pdo_getcolumn('jy_jdpm_member',array('mid'=>$id),'mid');
			pdo_update('core_members',array('password'=>$data['pwd']),array('id'=>$mid));
		}
		
		pdo_update('jy_jdpm_member',$data,array('mid'=>$id));
		exi('修改成功','','list');
	}else{
		$insert=array('username'=>trim($post['username']),'salt'=>random(10));
		$insert['password']=encryptPwd(trim($post['password']));
		$insert['createtime']=TIMESTAMP;
		$insert['from_os']=get_os();
		$insert['uniacid']=$_SESSION['uniacid'];
		pdo_insert('core_members',$insert);
		$uid=pdo_insertid();
		$data['mid']=$uid;
		$data['createtime']=time();
		$data['reg_ip']=getip();
		pdo_insert('jy_jdpm_member',$data);
		exi('添加成功','','list');
	}
	
}
if($_RQ['op']=='sendsms'){
	$id=intval($_RQ['mid']);
	$item['id']=$id;
	$htmls=array(
		'type'=>'edit',
		'post'=>'set',
		'desc'=>'站内信',
		'edit'=>array(
			'0'=>array('type'=>'text','title'=>'消息内容','name'=>'sms'),
			
		)
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$id=intval($post['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	
	$data=array('content'=>$post['sms'],'type'=>'系统提示','createtime'=>time(),'mid'=>$id,'uniacid'=>$_SESSION['uniacid']);
	pdo_insert('jy_jdpm_mysms',$data);
	exi('发送成功');
}
if($_RQ['op']=='credit'){
	$id=intval($_RQ['mid']);
	$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
	$aliv=$aliv?sprintf("%.2f", $aliv):0.00;
	$item['credit']='当前：'.$item['wallet_pledge'].'     冻结：'.$item['wallet_pledge_freeze'].'     可用：'.$aliv;
	$alivlim=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
	$alivlim=$alivlim?sprintf("%.2f", $alivlim):0.00;
	$item['xy']='当前：'.$item['wallet_limsum'].'     冻结：'.$item['wallet_limsum_freeze'].'     可用：'.$alivlim;
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'username',
		'desc'=>'账户信息编辑',
		'edit'=>array(
			array('type'=>'string','title'=>'用户账号','read'=>true,'name'=>'username'),
			array('type'=>'string','title'=>'账户余额','read'=>true,'name'=>'credit'),
			array('type'=>'string','title'=>'信誉额度','read'=>true,'name'=>'xy'),
			array('type'=>'radio','title'=>'操作项','name'=>'do','options'=>'do'),
			array('type'=>'radio','title'=>'动作','name'=>'act','options'=>'act'),
			array('type'=>'string','title'=>'输入金额','name'=>'money'),
			array('type'=>'string','title'=>'备注','name'=>'remark'),
		)
	);
	$return['do']=array('1'=>'账户余额','2'=>'信用额度');
	$return['act']=array('1'=>'加','2'=>'减','3'=>'冻结','4'=>'解冻');
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='username'){
	$post=get_postdata();
	$id=intval($post['mid']);
	if(!$id){
		exi('参数错误！','error');
	}
	$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if(!$post['do'] || !$post['act'] || !$post['money']){
		exi('操作项，动作和金额都需要填写','error');
	}
	if($post['money'] < 0 || !is_numeric($post['money'])){
		exi('必须是大于零的整数或布尔型','error');
	}
	$no='plg'.time().rand(10000,99999);
	if($post['do']==1){
		if($post['act']==1){
			$post['money']=price($post['money']);
			$post['remark']=$post['remark']?$post['remark']:'管理员充值';
			$data['wallet_pledge']=$post['money']+$item['wallet_pledge'];
			$aliv=$data['wallet_pledge']-$item['wallet_pledge_freeze'];
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'channel'=>'1','create_time'=>time(),'remarks'=>$post['remark'],'money'=>$post['money'],'type'=>0);
			pdo_insert('jy_jdpm_money_log',$data2);
		}
		if($post['act']==2){
			$post['money']=price($post['money']);
			$post['remark']=$post['remark']?$post['remark']:'管理员出金';
			$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data['wallet_pledge']=$item['wallet_pledge']-$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'channel'=>'2','create_time'=>time(),'remarks'=>$post['remark'],'money'=>$post['money'],'type'=>0);
			pdo_insert('jy_jdpm_money_log',$data2);
		}
		if($post['act']==3){
			$post['money']=price($post['money']);
			$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			//冻结资金增加
			$data['wallet_pledge_freeze']=$item['wallet_pledge_freeze']+$post['money'];	
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'channel'=>'2','create_time'=>time(),'remarks'=>$post['remark']?$post['remark']:'手动冻结','money'=>$post['money'],'type'=>1);
			pdo_insert('jy_jdpm_money_log',$data2);
		}
		if($post['act']==4){
			$post['money']=price($post['money']);
			$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			if($item['wallet_pledge_freeze']<$post['money']){
				exi('当前可解冻余额不足'.$post['money'],'error');
			}
			$aliv=$aliv+$post['money'];
			//冻结资金减少
			$data['wallet_pledge_freeze']=$item['wallet_pledge_freeze']-$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'channel'=>'1','create_time'=>time(),'remarks'=>$post['remark']?$post['remark']:'手动解冻','money'=>$post['money'],'type'=>1);
			pdo_insert('jy_jdpm_money_log',$data2);
		}
		
	}elseif($post['do']==2){
		if($post['act']==1){
			$post['money']=price($post['money']);
			$data=array('wallet_limsum'=>$post['money']+$item['wallet_limsum']);
			$aliv=$data['wallet_limsum']-$item['wallet_limsum_freeze'];
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_deposit','createtime'=>time(),'annotation'=>$post['remark'],'income'=>$post['money'],'balance'=>$data['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
		if($post['act']==2){
			$post['money']=price($post['money']);
			$aliv=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data=array('wallet_limsum'=>$item['wallet_limsum']-$post['money']);			
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_deduct','createtime'=>time(),'annotation'=>$post['remark'],'expend'=>$post['money'],'balance'=>$data['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
		if($post['act']==3){
			$post['money']=price($post['money']);
			$aliv=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data=array('wallet_limsum_freeze'=>$item['wallet_limsum_freeze']+$post['money']);			
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_freeze','createtime'=>time(),'annotation'=>$post['remark'],'expend'=>$post['money'],'balance'=>$item['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
		if($post['act']==4){
			$post['money']=price($post['money']);
			$aliv=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
			if($item['wallet_limsum_freeze']<$post['money']){
				exi('当前可解冻余额不足'.$post['money'],'error');
			}
			$aliv=$aliv+$post['money'];
			$data=array('wallet_limsum_freeze'=>$item['wallet_limsum_freeze']-$post['money']);			
			pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_unfreeze','createtime'=>time(),'annotation'=>$post['remark'],'income'=>$post['money'],'balance'=>$item['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
	}

	exi('操作成功','',manage_url('jy_jdpm/membermoney/',true));
}
if($_RQ['op']=='realname'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid']
	);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('mid','idcard_check','wallet_pledge','idcard','truename');
	$list=pdo_getslice('jy_jdpm_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['email']=$item['email']?$item['email']:'无';				
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户管理'),
			array('op'=>'edit','title'=>'添加用户'),
		),
		'list'=>array('key'=>'mid','data'=>'list','delall'=>false,'edit'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'username','title'=>'用户账号','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'truename','title'=>'姓名','type'=>'string'),
			array('name'=>'idcard','title'=>'身份证号','type'=>'string'),
			array('name'=>'idcard_check','title'=>'认证状态','type'=>'radio','options'=>'check'),
			
			
			'action'=>array(	
			array('op'=>'check','title'=>'实名认证','type'=>'modal','plugin'=>'jy_jdpm'),
				
		),
		)),
	);
	$return['check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	$id=intval($_RQ['mid']);
	$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']),array('mid','avatar','username','nickname','truename','idcard','idcard_check','idcard_front','idcard_behind'));
	$htmls=array(
		'type'=>'edit',
		'post'=>'docheck',
		'desc'=>'实名认证',
		'edit'=>array(
			array('type'=>'string','title'=>'登录账号','name'=>'username','read'=>true),
			array('type'=>'string','title'=>'真实姓名','name'=>'truename'),
			array('type'=>'string','title'=>'身份证号','name'=>'idcard'),
			array('type'=>'image','title'=>'身份证正面照片','name'=>'idcard_front'),
			array('type'=>'image','title'=>'身份证反面照片','name'=>'idcard_behind'),
			array('name'=>'idcard_check','title'=>'实名认证','type'=>'radio','options'=>'check'),
			
		)
	);
	$return['check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='docheck'){
	$post=get_postdata(); 
	$id=intval($post['mid']);
	if(!$id){
		exi('参数错误！','error');
	}	
	$data=array('truename'=>trim($post['truename']),'idcard'=>trim($post['idcard']),'idcard_front'=>$post['idcard_front'],'idcard_behind'=>$post['idcard_behind'],'idcard_check'=>$post['idcard_check'],);
	pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$mobile = pdo_getcolumn('jy_jdpm_member',array('mid'=>$id),'mobile');
	if($mobile){
		//$this->model('notice')->set_sms($mobile,'您的身份证验证成功!',4);
	}
	if($post['idcard_check'] == 3){
		$msg = '实名验证审核失败!请重新提交！';
	}
	if($post['idcard_check'] == 2){
		$msg = '您的身份证验证成功!';
	}
	$this->model('notice')->set_websms($msg,0,$id,'jy_jdpm/member.safety/idcard/');
	
	exi('操作成功');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['mid']);
	if($id){
		$mid=pdo_getcolumn('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']),'mid');	
		pdo_delete('core_members',array('id'=>$mid,'uniacid'=>$_SESSION['uniacid']));
		pdo_delete('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$mid=pdo_getcolumn('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']),'mid');	
				pdo_delete('core_members',array('id'=>$mid,'uniacid'=>$_SESSION['uniacid']));
				pdo_delete('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}